<?php
namespace app\souther\controller;
use think\Controller;
use app\common\model\Config as ConfigModel;
/**
 *  配置列表 
 */
class Config extends Controller
{
	/**
     * [index  获取配置参数]
     * @author [南风]
     * @return mixed
     */
	public function index()
	{
		$configModel = new ConfigModel();

		$list = $configModel->getAllConfig();

		$config = [];

        foreach ($list as $k => $v) {

            $config[trim($v['name'])] = $v['value'];

        }

        $urlArr = array (
            'https://upload-z0.qiniup.com' => '华东 https://upload-z0.qiniup.com',
            'https://upload-z1.qiniup.com' => '华北 https://upload-z1.qiniup.com',
            'https://upload-z2.qiniup.com' => '华南 https://upload-z2.qiniup.com',
            'https://upload-na0.qiniup.com' => '北美 https://upload-na0.qiniup.com',
            'https://upload-as0.qiniup.com' => '东南亚 https://upload-as0.qiniup.com',
        );
        // dump($config);die;
        return $this->fetch('',[
            'config'=>$config,
            'urlArr'=>$urlArr
        ]);
	}
    /**
     * [save  批量保存配置]
     * @author [南风]
     * @param $config
     */
    public function save($config){
        $configModel = new ConfigModel();
        if($config && is_array($config)){          
            foreach ($config as $name => $value) {
                $map = array('name' => $name);
                $configModel->SaveConfig($map,$value);
            }
        }
        cache('db_config_data',null);
        writelog('修改配置');

        $this->success('保存成功！');
    }
}